import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression

# 导入 bitcoin数据 BCHAIN-MKPRU.csv
bcc_df = pd.read_csv('BCHAIN-MKPRU.csv')

# 打印预览
print(bcc_df)

# 导入 gold数据 LBMA-GOLD.csv
gold_df = pd.read_csv('LBMA-GOLD.csv')

# 打印预览
print(gold_df)
# 合并两项数据
data = pd.merge(bcc_df, gold_df, on='Date', how='outer')
data["USD (PM)"].fillna(method='ffill', inplace=True)
data["USD (PM)"].fillna(method='ffill', inplace=True)
data["USD (PM)"].fillna(method='bfill', inplace=True)

data.reset_index()
print(data)

b_corr = data.corr('spearman')

lrModel = LinearRegression()
x = np.array(data.index).reshape(-1, 1)

y = np.array(data['Value']).reshape(-1, 1)

lrModel.fit(x, y)

print(lrModel.score(x, y))

print("==================")

print(lrModel.predict([[1821], [1853.1]]))

print(lrModel.coef_[0][0])

# plt.scatter(x,y)
# plt.show()
